<%
Class User
'Catelog

private ThisMdb		'=	"L_cat"				'数据库
private sqlstr
private PageLimit	'=	"10"				'每页的条数
'-------------------------------------------
Property Get PThisMdb
	PThisMdb=ThisMdb
End Property
Property Let PThisMdb(catMdb)
	ThisMdb=catMdb
End Property
'
property Get pPageLimit
	pPageLimit = PageLimit
End property 
property let pPageLimit(pagel)
	PageLimit = pagel
End property 


'-------------------
public Function AddNew(arrs)				'传入一维数组
	if not isarray(arrs) then 
		AddNew = false
		exit Function
	End if
	if UserExists(arrs(1)) = true then 
		AddNew = false
		exit Function
	End if
	'on error resume next	
	Dim adors
	set adors=server.createobject("adodb.recordset")
	sqlstr ="select top 1 * from "&ThisMdb&" "
	adors.open sqlstr,conn,1,3
	'if not(adors.eof and adors.bof) then 
		adors.addnew
		adors("user_name")			=	arrs(1)
		adors("user_password")		=	arrs(2)
		adors("user_level")			=	arrs(3)
		adors("user_email")			=	arrs(4)
		adors.update 
	'End if 
		If Err Then
			response.write (err.Description)
			err.Clear
			AddNew = false 
		else
			AddNew = true
		End if
	adors.close
	Set adors=nothing 

End Function
public Function Delete(user_id)
		sqlstr="delete from  "&ThisMdb&"  where [user_id]="&user_id&""
		on error resume next
		conn.execute(sqlstr)
		If Err Then
			response.write (err.Description)
			err.Clear
			Delete = false 
		else
			Delete = true
		End if

End Function 
'---------------------
public Function GetLimitInfo(pages,user_level)
	if not isnumeric(pages) then pages=1
	if pages < 1 then pages = 1 
		Dim tempall:tempall= GetAllResult(user_level)
	if pages * PageLimit >tempall then pages =  tempall/PageLimit
	pages= int(pages+0.5)
		
		if pages <=1 then 
			sqlstr = "select top "&PageLimit&"  [user_id],[user_name],[user_level],[user_email] from "&ThisMdb&" where 1  "
		else
			sqlstr = "select top "&PageLimit&"  [user_id],[user_name],[user_level],[user_email] from "&ThisMdb&" where ([user_id] not in (select top "&(pages-1)*PageLimit&" [user_id] from "&ThisMdb&" order by [user_id] desc )) "
		End if 
	if isnumeric(user_level) and user_level > 0 then 
		sqlstr = sqlstr & " and  ([user_level]= "&user_level&") "
	End if
		sqlstr = sqlstr & " order by [user_id] desc"
	GetLimitInfo = GetRows(sqlstr)
	
End Function 

public Function GetAllResult(user_level)'没有递归计数
	if isnumeric(user_level) and user_level > 0 then 
		sqlstr="select count(*) from "&ThisMdb&" where [user_level]="&user_level&""
	else
		sqlstr="select count(*) from "&ThisMdb&"  "
	End if
	GetAllResult = GetOne(sqlstr)
End Function 
public Function GetById(ids)
	sqlstr="select [user_id],[user_name],[user_level],[user_email] from "&ThisMdb&" where [user_id]="&ids&"  "
	GetById =  GetRows(sqlstr) 
End Function 

public Function Edit(arrstr)
	if not isarray(arrstr) then 
		Edit = false
		exit Function
	End if
	sqlstr ="select count(*) from "&ThisMdb&" where [user_id]<>"&arrstr(0)&" and  [user_name]='"&arrstr(1)&"'"
		if GetOne(sqlstr)>0 then 
			Edit = false 
			exit Function
		End if 

	set rs=server.createobject("adodb.recordset")
	sqlstr ="select top 1 * from "&ThisMdb&" where [user_id]="&arrstr(0)&"  "
	on error resume next
	rs.open sqlstr,conn,1,3
	if not(rs.eof and rs.bof) then 
		rs("user_name")			=	arrstr(1)
		if len(arrstr(2))<> 0 then 	rs("user_password")		=	arrstr(2)
		rs("user_level")		=	arrstr(3)
		rs("user_email")		=	arrstr(4)
		rs.update 
	End if 
		If Err Then
			response.write (err.Description)
			err.Clear
			Edit = false 
		else
			Edit = true
		End if
	rs.close
	Set rs=nothing 

End Function 
'---------------------
private Function UserExists(user_name)
	Dim sql
	sql ="select count(*) from  "&ThisMdb&" where [user_name]='"&user_name&"' "
	if GetOne(sql)>0 then 
		UserExists =true
	else
		UserExists =false 
	End if
End Function 


'-------------------------------------------
End class
%>